import urllib.parse
import urllib.request

url = "https://www.baidu.com/s?"
data = {
    "wd": "周杰伦",
    "sex": "男",
    "location": "台湾省"
}
param = urllib.parse.urlencode(data)  # 参数转Unicode编码
headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 "
                  "Safari/537.36 Edg/134.0.0.0"
}
# 定制请求头
request = urllib.request.Request(url + param, None, headers)
response = urllib.request.urlopen(request)
content = response.read().decode("utf-8")
print(content)
